package com.qdu.mq;
import com.alibaba.fastjson.JSON;
import com.qdu.entity.Mytrace;
import com.qdu.service.impl.MytraceServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Slf4j
@Component
@RabbitListener(queues = "addMytraceQueue")
public class DemoQueueConsumer {

    @Autowired
    MytraceServiceImpl mytraceService;

    /**
     * 消息消费
     * @RabbitHandler 代表此方法为接受到消息后的处理方法
     */
    @RabbitHandler
    public void recieved(List<Mytrace> mytraces) {
//        Collections.sort(mytraces, Comparator.comparing(Mytrace::getTheFirstDate));
        mytraceService.saveBatch(mytraces);
    }

}